import java.util.Scanner;

public class demo1 {
    public static int fun(int n) {
        int a=0;
        int b=1;
        int c=1;
        while(c<n) {
            a=b;
            b=c;
            c=a+b;
        }
        if(c==n) {
            return 0;
        } else {
            return c-n>n-b?n-b:c-n;
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(fun(n));
    }
}
